<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%     
	String path = request.getContextPath();     
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";     
%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>修改密码</title>
    <base href="<%=basePath%>"/>
    <%@ include file="../cuv_include.jsp"%>
    <style type="text/css">
  		fieldset,legend,form,table,tr,td,textarea{margin:0;padding:0}
  		form label {font-weight:bold;}
    	table{margin:10px 10px};
  		td{line-height: 40px;}
		input[type="text"]{width:250px;}
		input[type="password"]{width:250px;}
		input[type="textarea"]{width:250px;}   		
    </style>
    
	<script type="text/javascript">
	  $(document).ready(function(){

          var options = {dataType: 'json', beforeSubmit: beforeSubmit, success: process};
          $("#userForm").submit(function(){
              $(this).ajaxSubmit(options);
              return false;
          });

          $("#p_error").hide();
	  });

        function beforeSubmit() {
	        if(isEmpty($("#oldPassword").val())) { alert("旧密码不能为空！"); return false; }

	        if(!validatePassword($("#oldPassword").val(), 4, 22)) { alert("旧密码不符合规格！"); return false; }

	        if(isEmpty($("#password1").val())) { alert("新密码不能为空！"); return false; }

	        if(!validatePassword($("#password1").val(), 4, 22)) { alert("新密码不符合规格！"); return false; }

	        if(isEmpty($("#password2").val())) { alert("确认密码不能为空！"); return false; }

	        if(!validatePassword($("#password2").val(), 4, 22)) { alert("确认密码不符合规格！"); return false; }

            return true;
        }

        function process(responseJson) {
          if(responseJson.code == 0) {
              $('#error_label').text("错误信息：" + responseJson.message);
              $("#p_error").show();
              return;
          }
          history.back();
        }
	</script>
  </head>
  
  <body>
  <div>
    <fieldset>
      <legend>修改密码：</legend>
      <form id="userForm" method="post" action="personal/pass.do">
      	<p id = "p_error" style = "margin:10px 10px;">
      	    <label id="error_label" style="color:red;"></label>
      	</p>
        <table>
          <tr>
            <td><label for="oldPassword">旧密码：</label></td>
            <td>
              <input type="password" name="oldPassword" id="oldPassword" value="${oldPassword}" />
              <font color="red">&nbsp;*&nbsp;&nbsp;</font>
              <label for="oldPassword">只能由字母、数字、[_~!@#$%^&*+-]组成，字母开始，4～22位</label>
            </td>
          </tr> 
          <tr>
            <td><label for="password1">新密码：</label></td>
            <td>
              <input type="password" name="password1" id="password1" value="${password1}" />
              <font color="red">&nbsp;*&nbsp;&nbsp;</font>
              <label for="password1">只能由字母、数字、[_~!@#$%^&*+-]组成，字母开始，4～22位</label>
            </td>
          </tr> 
          <tr>
            <td><label for="password2">确认密码：</label></td>
            <td>
              <input type="password" name="password2" id="password2" value="${password2}" />
              <font color="red">&nbsp;*&nbsp;&nbsp;</font>
              <label for="password2">只能由字母、数字、[_~!@#$%^&*+-]组成，字母开始，4～22位</label>
            </td>
          <tr>
            <td></td>
            <td>
            	<input type="submit" id="btn_update" value="提交" style="width:80px;" />
            	<input type="button" id="btn_back" value="返回" onclick="history.back();" style="width:80px;" />
            </td>
          </tr>
        </table>
      </form>
    </fieldset>
  </div>    
  </body>
</html>